// yiliao/wodetiwen/wodetiwen.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tab: ["未回答", "已回答"],
    hide: true, //表单显示与隐藏  true隐藏  false显示
    daIndex: null,
    current: 0,
    values: "",
  },
  close: function() {
    this.setData({
      hide: true
    })
  },
  tab: function(e) {
    var that = this
    var openid = wx.getStorageSync('openid')
    console.log(e.currentTarget.dataset.index)
    if (e.currentTarget.dataset.index == 0) {
      app.util.request({
        'url': 'entry/wxapp/Allquestwei',
        data: {
          openid: openid
        },
        success: function(res) {
          console.log(res)
          var arrs = res.data.data;
          that.setData({
            wenda: arrs,
          })
        },
        fail: function(err) {
          console.log(err)
        },
      }) //未回答

    } else {

      app.util.request({
        'url': 'entry/wxapp/Allquestyi',
        data: {
          openid: openid
        },
        success: function(res) {
          console.log(res)
          var arrs = res.data.data;
          that.setData({
            wenda: arrs,
          })
        },
        fail: function(err) {
          console.log(err)
        },
      })
    }
    this.setData({
      current: e.currentTarget.dataset.index
    })
  },
  huida: function(e) {
    console.log(e)
    let that = this;
    var qid = e.currentTarget.dataset.id
    let i = e.currentTarget.dataset.index;
    that.setData({
      daIndex: i,
      hide: false,
      qid: qid
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var bgc = wx.getStorageSync('color')
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
    // this.getInfo();
    // console.log(this.getInfo('entry/wxapp/Allerciquestion'))
    var that = this
    var openid = wx.getStorageSync('openid');
    var zid = options.zid
    that.setData({
      zid: zid
    })
    // app.util.request({
    //   'url': 'entry/wxapp/Allquestyi',
    //   data: {
    //     openid: openid
    //   },
    //   success: function(res) {
    //     console.log(res)
    //     var arrs = res.data.data;
    //     that.setData({
    //       wenda: arrs,
    //     })
    //   },
    //   fail: function(err) {
    //     console.log(err)
    //   },
    // })

    app.util.request({
      'url': 'entry/wxapp/Allquestwei',
      data: {
        openid: openid
      },
      success: function(res) {
        console.log(res)
        var arrs = res.data.data;
        that.setData({
          wenda: arrs,
        })
      },
      fail: function(err) {
        console.log(err)
      },
    })
    that.setData({
      bgc: bgc
    })
  },
  //回答详情
  answerDetailClick: function(e) {
    console.log(e)
    var zid = e.currentTarget.dataset.zid
    var user_openid = e.currentTarget.dataset.openid
    var qid = e.currentTarget.dataset.qid
    // wx.navigateTo({
    //   url: '/hyb_yl/doc_answer_detail/doc_answer_detail',
    // })
    wx.navigateTo({
      url: '/hyb_yl/userLife/pages/zhuan_da/zhuan_da?zid=' + zid + '&user_openid=' + user_openid + '&qid=' + qid,
    })
  },
  previewImages: function(e) {
    var that = this;
    var current = e.currentTarget.dataset.src;
    var qid = e.currentTarget.dataset.qid;
    var qusetiontype = that.data.wenda;
    var imgs = [];
    for (var i = 0; i < qusetiontype.length; i++) {
      if (qusetiontype[i].qid == qid) {
        imgs = qusetiontype[i].user_picture;

      }
    }
    wx.previewImage({
      current: current, // 当前显示图片的http链接  
      urls: imgs // 需要预览的图片http链接列表  
    })

  },
  previewImage: function(e) {
    var that = this;
    var current = e.currentTarget.dataset.src;
    var qid = e.currentTarget.dataset.qid;
    var qusetiontypes = that.data.wenda;
    var imgs = [];
    for (var i = 0; i < qusetiontypes.length; i++) {
      if (qusetiontypes[i].qid == qid) {
        imgs = qusetiontypes[i].user_picture;

      }
    }
    wx.previewImage({
      current: current, // 当前显示图片的http链接  
      urls: imgs // 需要预览的图片http链接列表  
    })

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    // var that = this
    // var openid = wx.getStorageSync('openid')
    // app.util.request({
    //   'url': 'entry/wxapp/Allquestyi',
    //   data: {
    //     openid: openid
    //   },
    //   success: function(res) {
    //     console.log(res)
    //     var arrs = res.data.data;
    //     that.setData({
    //       wenda: arrs,
    //     })
    //   },
    //   fail: function(err) {
    //     console.log(err)
    //   },
    // })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})